<?php
namespace Management\Controller;
use Think\Controller;
class LoginController extends Controller {

	 protected $config = array (
				  'fontSize' => '14',
				  'length' => '4',
				  'useNoise' => false,
				  'useCurve' => false,
				  'imageW' => 100,
				  'imageH' => 35,
				  'fontttf' => '',
				  'bg' => 
				  array (
					0 => '255',
					1 => '255',
					2 => '255',
				  ),
				  'useImgBg' => false,
				  'codeSet' => '',
				  'useZh' => false,
				  'zhSet' => '风吹来滴砂落在悲伤的眼里谁都知道我在等你',
				  'expire' => 1800,
				  'seKey' => 'ThinkPHP.CN',
				  'reset' => false,
				);


    public function index(){
//		$configArr = require(rtrim(__PHYSICS__,'\\').'/Common/Conf/site.cn.php');
//		$this->assign('comName',$configArr['com_name'][val]);// 赋值

		$this->display('index');
		
    }
	
	public function sendAdminValid(){
	    $config = $this->config;
		if(!$config['codeSet'])unset($config['codeSet']);
		if(!$config['zhSet'])unset($config['zhSet']);
	
		$Verify = new \Think\Verify($config);
		$Verify->entry();
	}	
	
//	public function ajaxCheckValid(){
//		$config = $this->config;
//		$verify = new \Think\Verify($config);
//		$valid = I('valid');
//		$res = $verify->check($valid);
//		echo $res?1:0;exit;
//	}
	
//	public function ajaxCheckUser(){
//		$username = I('username');
//		$user = M('user');
//		$user_id = $user->where('username="'.$username.'"')->getField('id');
//		echo $user_id?1:0;exit;
//	}
//
//	public function ajaxCheckPwd(){
//		$username = I('username');
//		$password = I('password','','string');
//		$user = M('user');
//		$user_id = $user->where('username="'.$username.'" AND password="'.md5($password).'"')->getField('id');
//
//		echo $user_id?1:0;exit;
//	}
	
	public function userLogin(){
	
		header('Content-Type:text/html;charset=utf-8');	
		$username = I('admin_username');
		$password = I('admin_password','','string');
		$user = D('Management/User');
		
		 if(empty($username) || empty($password)){
			   $errorMsg = '请填写账号和密码！';
			   $this->error($errorMsg);
		 }
	 
		if ($username && $password) {
				$result = $user->login($username, $password);
				
				if($result==1) {
				  //redirect(U('Index/index'));
                    $this->success('登录成功',U('Index/index'));
				}else{
				  $errorMsg = $result;
				  $this->error($errorMsg);
				}
				   
		} else {
			$errorMsg = '请填写账号和密码！';
			$this->error($errorMsg);
		}	
	
	}
	
	public function userlogout(){
		$user = D('Management/User');
		$user->logout();
		redirect(U('Login/index'));
	}
	
	
	
	
	
	
	
		
	
	
}